﻿using Lifang.Common;
using Lifang.Entites;
using System;
using System.Collections.Generic;
using System.Text;

namespace Lifang.Dao
{
    public class PageConfigDao : BaseDao<DP_PageConfig>
    {
        public PageConfigDao() : base()
        {

        }

        public PageConfigDao(LoginUserModel loginUserModel) : base(loginUserModel)
        {

        }


        #region  新增或保存实体
        public CommonResult SaveOrUpdateMod(DP_PageConfig mod)
        {
            var re = new CommonResult();
            if (mod.Id == 0)
            {
                SetCreateInfo(mod);
                mod.SetDefaultValue();
                var i = new DapperHelper().InserData(mod, new SqlNote("蔡小光", "新增数据"));
                if (i > 0)
                {
                    return re;
                }
            }
            else
            {
                SetUpdateInfo(mod);
                mod.SetDefaultValue();
                var old = new DapperHelper().SelectModel<DP_PageConfig>(mod.Id, new SqlNote("蔡小光", "查询单个实体"));
                var i = new DapperHelper().UpdateExecute(mod, new SqlNote("蔡小光", "更新数据"));
                if (i > 0)
                {                    
                    return re;
                }

            }
            return re;
        }
        #endregion


        #region 设置新增或修改人信息
        public void SetCreateInfo(DP_PageConfig mod)
        {
            mod.CreateUserNo = OpUser.UserNo;
            mod.CreateUserName = OpUser.UserName;
            mod.CreateDateTime = DateTime.Now;
        }

        public void SetUpdateInfo(DP_PageConfig mod)
        {
            mod.UpdateUserNo = OpUser.UserNo;
            mod.UpdateUserName = OpUser.UserName;
            mod.UpdateDateTime = DateTime.Now;
        }
        #endregion

    }
}
